<template>
<div>
  <div style="color:white;font-size:15pt;margin-bottom:10px">创建用户默认密码为1,最多只能创建20个用户</div>
  
  <ConfigDataList :cate="cate" :cols="cols">
  
  </ConfigDataList>
</div>
</template>
<script>
import ConfigDataList from "@/components/ConfigDataList";
import { getUser } from "@/utils/auth";
import {findComponent} from "@/utils/ui";
import linq from "linq";
 import {search教师基本情况,get教师基本情况ByGH} from "@/api/教师基本情况"
import { add权限, delete权限, update权限, get权限 } from "@/api/权限.js";
export default {
  components: {
    ConfigDataList
  },
  data() {
    return {
      search_str:'',
      cate: "A14-1权限配置",
    
      cols: [
       { label: "工号", prop: "GH" },
       { label: "姓名", prop: "XM" },
       { label: "录入权限", prop: "ROLE_INPUT" },  
      { label: "审核权限", prop: "ROLE_AUDIT" },  
      { label: "查看权限", prop: "ROLE_VIEW" },  
      ]
    };
  },        
  methods:{
     onDlgCreated(model){
       
      
      //  var role_input= findComponent(this, "ROLE_INPUT");
      //  var role_input= findComponent(this, "ROLE_INPUT");
      //   var role_input= findComponent(this, "ROLE_INPUT");
   
      //  var view_right = linq.from(view_right).select("{value:$}").toArray();
      // var input_right = linq.from(input_right).select("{value:$}").toArray();
      // role_input.value = input_right;
      // role_audit.$attrs.items = input_right;
      // role_view.$attrs.items = view_right;
      //
      //
    },
    mysearch(){
      
    },
    async fetchData() {
      
      var user = getUser();
      var datas = await get权限(user.XXID,user.CJPC);
    
      return datas;
    }, 
    async  onChange(model, field, value) {
 
      //
         if(field == "GH"){
         if(value == "error"){
           console.log("error")
          model.GH=""
          model.XM= "";
            model.BMMC = "";
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
        
           console.log("udpate ")
           model.BMMC = d1[0].BMMC;
          model.GH=d1[0].GH;
          model.XM= d1[0].XM;
         
         
         
         }
       }
      //
    },
    add_check(model,list){
      var temp = linq.from(list).firstOrDefault(e=>e.GH == model.GH);
      if(temp){
        return  "该用户已经定义权限"
      }
    },
    
     onadd(model) {
      //
    
      //
      var temp = JSON.parse(JSON.stringify(model))
      var user = getUser();
      temp.CJPC = user.CJPC;
      temp.XXID = user.XXID;
      temp.PASSWORD="1";
    
      return new Promise(async (resolve,reject)=>{
         try{
          console.log(JSON.stringify(temp));
    
          var model = await add权限(temp);


        
          resolve(model);
         }catch(e){
           reject(e);
         }
      })
    },
    onupdate(model) {
      //
        
        var temp = JSON.parse(JSON.stringify(model))
     
      return new Promise(async (resolve,reject)=>{
        try{
          var model = await update权限(temp);
          resolve(model);
        }catch(e){
          reject(e);
        }
      })
      //
    },
    ondelete(model) {
         
         var temp = JSON.parse(JSON.stringify(model))
         return new Promise(async (resolve,reject)=>{
           try{
         await delete权限(temp);
          resolve();
           }catch(e){
             reject(e);
           }
      })
    }
  }
};
</script>
<style>
</style>